package com.intellagric.controller.module.trace_produce;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.module.traceability.ProduceVo;
import com.intellagric.pojo.TraceProduce;
import com.intellagric.service.traceability.trace_produce.ProduceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/11/3
 * @DESC： 溯源模块农产品信息管理
 */
@Controller
public class ProduceController {

    @Autowired
    private ProduceService produceService;

    /**
     * 添加农产品信息
     * @Param produce
     * @return ResponseMessage
     */
    @RequestMapping("/produce/add")
    @ResponseBody
    public ResponseMessage add(TraceProduce produce) {
        //初始化信息
        produce.setId(UUID.randomUUID().toString().replaceAll("-",""));
        return produceService.addProduct(produce);
    }


    /**
     * 删除农产品信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/produce/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return produceService.deleteProduct(id);
    }

    /**
     * 修改农产品信息
     * @Param produce
     * @return ResponseMessage
     */
    @RequestMapping("/produce/edit")
    @ResponseBody
    public ResponseMessage edit(TraceProduce produce) {
        return produceService.editProduct(produce);
    }

    /**
     * 查询农产品信息
     * @return TraceProduce
     */
    @RequestMapping("/produce/{id}")
    @ResponseBody
    public TraceProduce get(@PathVariable String id) {
        return produceService.getProductById(id);
    }

    /**
     * 查询农产品信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/produce/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return produceService.getProductList();
    }
    /**
     * 查询农产品信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/produce/listByCreateBy")
    @ResponseBody
    public LayuiDataGridResult getList(String createBy) {
        return produceService.getProductList(createBy);
    }

    /**
     * 分页查询农产品信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/produce/page")
    @ResponseBody
    public LayuiDataGridResult getPage(int page,int limit) {
        return produceService.getProductPage(page,limit);
    }


    @RequestMapping("/produce/pageByCreateBy")
    @ResponseBody
    public LayuiDataGridResult getPage(int page,int limit,String createBy) {
        return produceService.getProductPage(page,limit,createBy);
    }

    /**
     * 多条件查询农产品信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/produce/query")
    @ResponseBody
    public LayuiDataGridResult getQueryList(ProduceVo produceVo) {
        return produceService.getProductByVo(produceVo);
    }
}
